package bishi.lixiang;

import java.util.Scanner;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2022/03/03 00:12
 */
public class _2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int  n = in.nextInt();in.nextLine();
        for(;n>0;){
            n--;
            String str = in.nextLine();
            int L = -1,O=-1,V=-1,E=-1;
            char[] cs = str.toCharArray();
            int res = 0;
            for(int i=0;i<cs.length;i++){
                switch(cs[i]){
                    case'L': L = i;break;
                    case'O': O = i;break;
                    case'V': V = i;break;
                    case'E': E = i;break;
                }
                int min = Math.min(Math.min(L,O),Math.min(V,E));
                if(min != -1){
                    res += (1+min);
                }
            }
            System.out.println(res);
        }
    }
}
